package org.example.interceptor;

import cn.hutool.jwt.JWT;
import cn.hutool.jwt.JWTUtil;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 */
public class JwtInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request,
                             HttpServletResponse response,
                             Object handler) {
        // 验证 JWT 逻辑
        String token = request.getHeader("Authorization");
        JWT claims = JWTUtil.parseToken(token);
        request.setAttribute("userInfo", claims);
        return true;
    }
}
